package com.mallcai.bigdata.ladon.controller.dashboard;

import com.mallcai.bigdata.ladon.controller.dashboard.form.SqlRunLogStaticForm;
import com.mallcai.bigdata.ladon.dpl.entity.dashboard.SqlRunLogStatic;
import com.mallcai.bigdata.ladon.service.dashboard.ISqlRunLogStaticService;
import com.mallcai.bigdata.ladon.service.report.IReportService;
import com.mallcai.bigdata.ladon.service.report.ISqlRunLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/report/logStatic")
@RestController
public class SqlRunLogStaticController {

    @Autowired
    private ISqlRunLogStaticService iSqlRunLogStaticService;
    @Autowired
    private ISqlRunLogService iSqlRunLogService;
    @Autowired
    private IReportService iReportService;

    //按照时间和报表获取平均请求时间的统计数据
    @RequestMapping("/getAvgTimeData")
    public List<SqlRunLogStatic> getAvgTimeData(@RequestBody @Validated SqlRunLogStaticForm form) {
        return iSqlRunLogStaticService.getAvgTimeData(form.getParams());
    }

    //按照时间和报表获取报表的总请求次数数据
    @RequestMapping("/getCountData")
    public List<SqlRunLogStatic> getCountData(@RequestBody @Validated SqlRunLogStaticForm form) {
        return iSqlRunLogStaticService.getCountData(form.getParams());
    }

    //按照报表获取前10个请求数最大的统计数据
    @RequestMapping("/getTopCount")
    public List<SqlRunLogStatic> getTopCount(@RequestBody @Validated SqlRunLogStaticForm form) {
        return iSqlRunLogStaticService.getTopCount(form.getParams());
    }

    //按照报表获取前10个平均请求时间最的统计数据
    @RequestMapping("/getTopAvgTime")
    public List<SqlRunLogStatic> getTopAvgTime(@RequestBody @Validated SqlRunLogStaticForm form) {
        return iSqlRunLogStaticService.getTopAvgTime(form.getParams());
    }

    @RequestMapping("/getReportStatistic")
    public Map<String, Object> getReportStatistic() {
        Map<String, Object> data = new HashMap<>();
        data.put("reportSize", iReportService.getReportSize());
        data.put("visitSize", iSqlRunLogStaticService.totalVisitSize());
        data.put("todayVisit", iSqlRunLogService.getTodayVisitSize());
        return data;
    }
}
